/**
 * Project Name: mmms-provider-user
 * File Name: DepartmentController
 * Package Name: com.scb.dev.mms.controller
 * Date: 2018/11/27 12:08 PM
 * Copyright (c) 2018, Wang, Haoyue All Rights Reserved.
 */
package com.scb.dev.mms.controller;

import com.scb.dev.mms.common.ResponseResult;
import com.scb.dev.mms.pojo.Department;
import com.scb.dev.mms.service.IDepartmentService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: DepartmentController
 * Description: Department Controller
 * Date: 2018/11/27 12:08 PM
 *
 * @author Wang, Haoyue
 * @version V1.0
 * @since JDK 1.8
 */
@RestController
@RequestMapping("/sm/department/")
@Api(value = "DepartmentController", description = "department API")
public class DepartmentController {

    @Autowired
    private IDepartmentService departmentService;

    /**
     * addDepartment: add department
     *
     * @param department
     * @return
     */
    @RequestMapping(value = "department", method = RequestMethod.POST)
    @ApiOperation(value="addDepartment", notes="Use this API to add a new department.")
    public ResponseResult addDepartment(@RequestBody
                                            @ApiParam(name="department",value="department entity")
                                                    Department department) {
        return departmentService.insertDepartment(department);
    }

    /**
     * deleteDepartment: delete a department
     *
     * @param departmentId
     * @return
     */
    @RequestMapping(value = "department/{departmentId}", method = RequestMethod.DELETE)
    @ApiOperation(value="deleteDepartment", notes="Use this API to delete a department.")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType ="path",name = "departmentId",value = "department id",required = true ,dataType = "String"),
    })
    public ResponseResult deleteDepartment(@PathVariable("departmentId") String departmentId) {
        return departmentService.deleteDepartment(departmentId);
    }

    /**
     * updateDepartment: update department
     *
     * @param department
     * @return
     */
    @RequestMapping(value = "department", method = RequestMethod.PUT)
    @ApiOperation(value="updateDepartment", notes="Use this API to update a department.")
    public ResponseResult updateDepartment(@RequestBody
                                               @ApiParam(name="department",value="department entity")
                                                       Department department) {
        return departmentService.updateDepartment(department);
    }

    /**
     * findOne: find department by id
     *
     * @param departmentId
     * @return
     */
    @RequestMapping(value = "department/{departmentId}", method = RequestMethod.GET)
    @ApiOperation(value="findOne", notes="Use this API to find a department by id.")
    @ApiImplicitParam(paramType ="path",name = "departmentId",value = "department id",required = true ,dataType = "String")
    public ResponseResult findOne(@PathVariable String departmentId) {
        return departmentService.queryOne(departmentId);
    }


    /**
     *
     * @MethodName: findIdAndName
     * @Description: find Id And Name
     *
     * @Params:
     * @Return: ResponseResult
     * @Date: 2018/12/2 20:27
     */
    @RequestMapping(value = "department/select", method = RequestMethod.GET)
    @ApiOperation(value="findIdAndName", notes="Use this API to find all departments' id and name.")
    public ResponseResult findIdAndName(){
        return departmentService.queryAllDepartmentIdAndName();
    }

    /**
     * findAllDepartment: find all department
     *
     * @return
     */
    @RequestMapping(value = "department", method = RequestMethod.GET)
    @ApiOperation(value="findAllDetails", notes="Use this API to find all departments' details.")
    public ResponseResult findAllDetails() {
        return departmentService.queryAllDetails();
    }


}
